package com.sec.android.app.myfiles.feature.Hover;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.widget.ImageButton;

import com.sec.android.app.myfiles.log.Log;

public class MediaAirViewImageButton extends ImageButton {

    private static final String MODULE = "VideoAirViewImageButton";

    private PlayableMediaHoverView mAirViewListener;

    public MediaAirViewImageButton(Context context) {
        super(context);
    }

    public MediaAirViewImageButton(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MediaAirViewImageButton(Context context, AttributeSet attrs,
                                   int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setAirViewManager(PlayableMediaHoverView manager) {
        mAirViewListener = manager;
    }

    @Override
    public void onHoverChanged(boolean hovered) {
        super.onHoverChanged(hovered);
        Log.d(MODULE, "onHoverChanged hovered - " + hovered);
        if (mAirViewListener != null) {
            mAirViewListener.setBtnHovered(hovered);
            if (!mAirViewListener.isBtnHovered()) {
                mHoverHandler.sendEmptyMessageDelayed(mHoverHandler.obtainMessage().what, 150);
            }
        }
    }

    private final Handler mHoverHandler = new Handler(new Handler.Callback() {

        @Override
        public boolean handleMessage(Message msg) {
            if (!mAirViewListener.isLayoutHover() && !mAirViewListener.isBtnHovered()) {
                mAirViewListener.dismissPopup();
            }
            return false;
        }
    });
}

